<?= flash() ?? ''; ?>

<div class="breadcrumb d-flex align-items-center px-3 js-scroll">
    <?php if(session('user_id')): ?>
        <div class="btn btn-icon me-3 hidden-lg hidden-md hidden-sm" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasNav" aria-controls="offcanvasNav">
            <i class="iconfont icon-user"></i>
        </div>
    <?php else: ?>
        <a role="button" class="btn btn-icon me-3 hidden-lg hidden-md hidden-sm" href="/user-login">
            <i class="iconfont icon-user"></i>
        </a>
    <?php endif; ?>
    <h2 class="w-100 fs-18 hand js-top"><?= $page_title ?? ''; ?></h2>
    <div class="dropdown">
        <button class="btn btn-icon" type="button" data-bs-toggle="dropdown" aria-expanded="false"><i class="iconfont icon-magic"></i></button>
        <div class="dropdown-menu dropdown-menu-end shadow-sm">
            <div class="dropdown-item p-3 border-bottom text-center arrow bg-white">
                <img class="mb-2" src="/img/magic.svg" width="48" height="48" alt="">
                <p class="fw-bold fs-18">主页优先显示热门帖子</p>
            </div>
            <a class="dropdown-item" href="#">
                <i class="iconfont icon-exchange me-2"></i>
                <span class="fw-bold">切换查看最新帖子</span>
            </a>
            <a class="dropdown-item" href="#">
                <i class="iconfont icon-settings me-2"></i>
                <span class="fw-bold">查看内容偏好设置</span>
            </a>
        </div>
    </div>
</div>

<?php if(!session('user_id')): ?>
    <div class="banner px-3 d-flex flex-column justify-content-center align-items-center border-bottom">
        <p class="fs-20 mb-2 fw-bold">登录之后，更精彩！</p>
        <div class="d-flex">
            <a role="button" class="btn btn-primary" href="/user/signin">登录</a>
            <a role="button" class="btn btn-outline ms-2" href="/user/signup">注册</a>
        </div>
    </div>
<?php else: ?>
    <?= mini\Template::partial('partials/_post', $data) ?>
<?php endif; ?>

<div class="alert p-4 border-0 border-bottom rounded-0 mb-0 text-center alert-dismissible fade show bg-gradient" role="alert">
    <b class="fs-20">每日帖不过３😉</b>
    <p class="mt-1 mb-3 text-muted">友情提示，发帖和回帖都需要<i class="squiggle">扣除１个金币</i>哦！</p>
    <a class="btn btn-secondary" href="/reward/">
        <i class="iconfont icon-present me-2"></i>领取今日登录奖励
    </a>
    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="关闭"></button>
</div>

<ul class="feed-list list-unstyled">
    <?php foreach ($posts[0] as $post): ?>
        <li class="feed-item d-flex" data-href="/post/show/<?= $post->id ?>" data-pid="<?= $post->id ?>">
            <a class="avatar" href="/user/profile/<?= $post->user_id ?>" data-letters="<?= mb_substr($post->username, 0, 1, 'UTF-8'); ?>"></a>
            <div class="d-flex flex-column w-100">
                <div class="d-flex align-items-center">
                    <a class="link-dark fw-bold fs-15 post-meta" href="/user/profile/<?= $post->user_id ?>"><?= $post->username; ?></a>
                    <a class="link-muted fs-15" href="/post/show/<?= $post->id ?>"><?= nice_time($post->created_at) ?></a>
                </div>
                <p class="typo-text"><?= $post->content ?></p>
                <?php if($post->images > 0): ?>
                    <?php if($post->type === 'gif'): ?>
                        <img class="img-fluid rounded align-self-baseline mt-2" data-gifffer="/upload/<?= $post->name ?>" alt="" loading="lazy" decoding="async">
                    <?php else: ?>
                        <img class="img-fluid rounded align-self-baseline mt-2" src="/upload/<?= $post->name ?>" alt="" loading="lazy" decoding="async">
                    <?php endif ?>
                <?php endif ?>
            </div>
            <div class="feed-item-count">
                <spap class="post-num">
                    <i><?= $post->comments ?></i>
                    <span class="list-triangle-border"></span>
                    <span class="list-triangle-body"></span>
                </spap>
            </div>
        </li>
    <?php endforeach; ?>
</ul>

<nav aria-label="Page navigation">
    <ul class="pagination justify-content-center p-3">
        <li class="page-item"><a class="page-link" href="<?= $posts[1]->prevPage;?>"><span aria-hidden="true">&lsaquo;</span></a></li>
<?php foreach($posts[1]->listPage as $k=>$v): ?>
    <?php if($k == $posts[1]->currentPage): ?>
        <li class="page-item"><a class="page-link active" href="<?= $v ?>"><?= $k ?></a></li>
    <?php else: ?>
        <li class="page-item"><a class="page-link" href="<?= $v ?>"><?= $k ?></a></li>
    <?php endif ?>
<?php endforeach ?>
        <li class="page-item"><a class="page-link" href="<?= $posts[1]->nextPage;?>"><span aria-hidden="true">&rsaquo;</span></a></li>
    </ul>
</nav>